package com.subway.babynote;

import com.subway.babynote.syncservice.syncapi;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;

public class more extends Activity {
	private static final int INVISIBLE = 0x00000004;
	Button login_button;
	Intent In;
	NotedbHelper notedb;
	FocusListView lv;
	String[] more_array;
	private LinearLayout linearLayout, statistics, sync, more;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.moremenu);
	
		login_button = (Button) findViewById(R.id.login_button);
		lv = (FocusListView) findViewById(R.id.list);
		lv.setTextFilterEnabled(true);
		more_array = getResources().getStringArray(R.array.more);
		lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
				more_array));
		In= new Intent();
	//	initTabFunction();
		notedb = new NotedbHelper(this);
		try {
			if (syncapi.getSyncImpl().getUser().isuser) {
				login_button.setVisibility(INVISIBLE);
				login_button.setClickable(false);
			}
		} catch (Exception e) {
			Log.v("statistics", "from DB e=" + e.getMessage());
		}
		
		lv.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

				
				switch (position) {
				// 
				case 0:
					In.setClass(more.this, myinfo.class);
					startActivity(In);
					break;
				case 1:
					In.setClass(more.this, feedback.class);
					startActivity(In);

					break;
				
				case 2:
					In.setClass(more.this, aboutus.class);
					startActivity(In);
					
					break;
				}
			}
		});
		

		
		login_button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
			
				In.setClass(more.this, login.class);
				startActivity(In);
			}
		});
	}
	
	public void QuitApp() {
		new AlertDialog.Builder(more.this).setTitle(getResources().getString(R.string.prompt)).setMessage(
				getResources().getString(R.string.confirmMessage)).setIcon(R.drawable.btn_close_normal).setPositiveButton(getResources().getString(R.string.confirm),
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {	
					
						finish();
					}
				}).setNegativeButton(getResources().getString(R.string.cancel),
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
					}
				}).show();

	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			QuitApp();
			return true;
			
		}
		return false;
	}
	
	public void onDestroy(){
		   notedb.close();
		   super.onDestroy();	  	   
		   
		}
}